//
//  CNetWorkRequest.h
//  Delicious
//
//  Created by apple on 11-11-8.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AppConfig.h"
#import "JSON.h"

#define HEADER          @"\r\n-----------------------------0x0x0x0x0x0x0x0x\r\n"
#define IMAGE_CONTNET   @"Content-Disposition: form-data; name=\"hck_img\"; filename=\"image.jpg\"\r\n"
#define CONTENTTYPE     @"Content-Type: application/octet-stream\r\n\r\n"
#define MULTIPART       @"multipart/form-data; boundary=---------------------------0x0x0x0x0x0x0x0x"
#define END             @"\r\n-----------------------------0x0x0x0x0x0x0x0x--\r\n"

typedef enum {Get, Post, PostImage}MethodType;
typedef enum {Icon, Image, Json}DataType;

@class AppConfig;

@protocol NetWorkRequestDelegate;

@interface CNetWorkRequest : NSObject

@property  (nonatomic, assign) id<NetWorkRequestDelegate>   m_Delegate;

@property  (nonatomic, assign) NSMutableURLRequest      *m_UrlRequest;
@property  (nonatomic, assign) NSURLConnection          *m_UrlConnection;
@property  (nonatomic, assign) NSMutableData            *m_Data;
@property  (nonatomic, assign) BOOL                     m_bIsLoaded;
@property  (nonatomic, assign) NSTimer                  *m_TimeOutTimer;

-(void)Stop;
-(void)SetRequestWithUrl:(NSString*)url Method:(MethodType)type Value:(NSData*)data IsSynchronous:(BOOL)issynchronous OutTime:(int)outtime;

-(void)RequestNoNetWork;
-(void)RequestTimeout:(NSTimer*)timer;

@end

@protocol NetWorkRequestDelegate <NSObject>

@optional
-(void)DidReceiveData:(CNetWorkRequest*)request Data:(NSMutableData*)data;
-(void)DidReceiveError:(CNetWorkRequest *)request Error:(NSError*)error;
-(void)DidRectiveTimeout:(CNetWorkRequest *)request;
-(void)DidStopRequestNoNet:(CNetWorkRequest *)request;

@end

